package com.enterprise.controller.manage;


import com.alibaba.fastjson.JSON;
import com.enterprise.controller.api.message.vo.MessageResp;
import com.enterprise.entity.Messages;
import com.enterprise.service.MessageService;
import com.enterprise.util.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.enterprise.service.Services;
import com.enterprise.controller.BaseController;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 后台查看留言管理
 * @author Cesiumai
 *
 */
@Controller
@RequestMapping("/manage/message/")
public class MessagesAction extends BaseController<Messages>{
	private static final String page_toList = "/manage/messages/messageList";
	private static final String page_toEdit = "/manage/messages/messageInfo";
	private static final String page_toAdd = "/manage/messages/messageInfo";
	public MessagesAction() {
		super.page_toList = page_toList;
		super.page_toEdit = page_toEdit;
		super.page_toAdd = page_toAdd;
	}
	
	@Autowired
	private MessageService messageService;

	@Override
	public Services<Messages> getService() {
		return messageService;
	}

	@RequestMapping("export")
	public void export(String[] ids,HttpServletResponse response) {
		List<MessageResp> list = new ArrayList<>();
		for (int i =0;i<ids.length;i++){
			Messages message = messageService.selectById(Integer.valueOf(ids[i]));
			MessageResp messageResp = new MessageResp();
			BeanUtils.copyProperties(message,messageResp);
			String gender;
			if ("m".equals(messageResp.getGender())){
				gender = "男";
			}else if ("f".equals(messageResp.getGender())){
				gender = "女";
			}else {
				gender ="未填写";
			}
			messageResp.setGender(gender);
			messageResp.setStatus("0".equals(messageResp.getStatus())?"未查看":"已查看");
			list.add(messageResp);
		}
		String[] title = {"留言序号","留言标题","留言人名字","留言人性别","留言人电话","留言人微信号","留言状态","留言人email","留言内容","留言时间"};
		ExcelUtil.export("客户留言",title,list,response);
	}


}
